import express, { Router } from 'express'
import * as commentController from './comment.controller'
import { authGuard, accessControl } from '../auth/auth.middleware'
import { filter } from './comment.middleware'
import { pagination } from '../post/post.middleware'

const router: Router = express.Router()

router.get('/comment', filter, pagination, commentController.index)
router.get('/comment/:commentId/replies', commentController.indexReplies)
router.post('/comment', authGuard, commentController.store)
router.post('/comment/:commentId/reply', authGuard, commentController.reply)
router.patch(
  '/comment/:commentId',
  authGuard,
  accessControl({ possession: true }),
  commentController.update
)

router.delete(
  '/comment/:commentId',
  authGuard,
  accessControl({ possession: true }),
  commentController.destory
)

export default router
